package web.java.d_test;

import static org.junit.Assert.*;

import java.util.List;

import org.junit.Test;

import web.java.c_Dao.BaseDao;

public class Demo01_testBaseDao {
	/**
	 * 测试BaseDao的更新
	 * */
	@Test
	public void testUpdate() throws Exception {
		BaseDao base=new BaseDao();
		String sql="UPDATE emp SET emp_gender=? WHERE emp_id=?;";
		String gender="男";
		int emp_id=15;
		Object[] obj={gender,emp_id};
		base.update(sql,obj);
	}
	/**
	 * 测试BaseDao的添加
	 * */
	@Test
	public void testAdd() throws Exception {
		BaseDao base=new BaseDao();
		String sql="INSERT INTO emp(emp_name,emp_age,emp_salary,emp_consume,emp_gender) VALUES(?,?,?,?,?);";
		Object[] obj={"测试数据二",33,9999,33333,"男"};
		int result=base.update(sql,obj);
		System.out.println(result);
	}
	/**
	 * 测试BaseDao的删除
	 * */
	@Test
	public void testDelete() throws Exception {
		BaseDao base=new BaseDao();
		String sql="DELETE FROM emp WHERE emp_id>=? AND emp_id<=?;";
		Object[] obj={22,23};
		int result=base.update(sql,obj);
		System.out.println(result);
	}
	/**
	 * 测试BaseDao的查询
	 * */
	@Test
	public void testSelect() throws Exception {
		BaseDao base=new BaseDao();
		String sql="SELECT * FROM emp where emp_id=?;";
		Object[] obj={10};
		List<Emp> lists=base.select(sql,obj,Emp.class);
		for(Emp emp:lists){
			System.out.println(emp);
		}
	}
}
